Aiming at the problems of slow detection speed, low precision, missed detection and false detection of current forest pest detection methods, a forest pest detection method based on attention model and lightweight YOLOv4 was proposed. Firstly, a dataset was constructed and preprocessed by using geometric transformation, random color dithering and mosaic data augmentation techniques. Secondly, the backbone network of YOLOv4 was replaced with a lightweight network MobileNetV3, and the Convolutional Block Attention Module (CBAM) was added to the improved Path Aggregation Network (PANet) to build the improved lightweight YOLOv4 network. Thirdly, Focal Loss was introduced to optimize the loss function of the YOLOv4 network model. Finally, the preprocessed dataset was input into the improved network model, and the detection results containing pest species and location information were output. Experimental results show that all the improvements of the network contribute to the performance improvement of the model; compared with the original YOLOv4 model, the proposed model has faster detection speed and higher detection mean Average Precision (mAP), and effectively solves the problem of missed detection and false detection. The proposed new model is superior to the existing mainstream network models and can meet the precision and speed requirements of real?time detection of forest pests.